//
//  SearchUserTableViewCell.swift
//  OnceNectar
//
//  Created by 法正磊 on 2018/2/5.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit
import Networking
import Alamofire
import PKHUD
import SwiftyJSON
protocol SearchUserTableViewCellDelegate: NSObjectProtocol {
    func attentionUser(parameters:[String:Any], btn:UIButton) -> Void
    func attentionCancelUser(parameters: [String:Any], btn:UIButton) -> Void 
}
class SearchUserTableViewCell: UITableViewCell {
    @IBOutlet weak var headImgView: BaseCircleImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var sexImgView: UIImageView!
    @IBOutlet weak var levelLabel: UILabel!
    @IBOutlet weak var matchLabel: UILabel!
    
    @IBOutlet weak var followButton: UIButton!
    var model: circleMemberListModel = circleMemberListModel()
    weak var delegate: SearchUserTableViewCellDelegate?
    override func awakeFromNib() {
        super.awakeFromNib()
        followButton.layoutIfNeeded()
        followButton.layer.cornerRadius = followButton.height / 2
        followButton.layer.borderColor = UIColor(hex: 0xE10000).cgColor
        followButton.layer.borderWidth = 1.0
        // Initialization code
    }
    
    func bindData(model: circleMemberListModel) -> Void {
        self.model = model
        
        headImgView.sd_setImage(with: appendUrl(suffix: model.headIcon!), completed: nil)
        nameLabel.text = model.nickname
        if model.sexy == "男" {
            sexImgView.image = UIImage(named: "user_gender_male")
        }else{
            sexImgView.image = UIImage(named: "user_gender_female")
        }
        if model.grade != nil {
            levelLabel.text = (model.grade?.neededScore)!
        }else {
            levelLabel.text = ""
        }
        matchLabel.text = "匹配度" + model.matchDegree!
        
        if model.isConcerned != nil {
            if model.isConcerned == "1" {
                followButton.isSelected = true
            }else{
                followButton.isSelected = false
            }
        }
        if model.concernType != nil {
            if model.concernType == "0" {
                followButton.isSelected = false
            }else{
                followButton.isSelected = true
            }
        }
        followButton.tag = Int(model.id!)!
        
    }
    
    @IBAction func attentionAct(_ sender: UIButton) {
        if sender.isSelected {
            self.delegate?.attentionCancelUser(parameters:  ["concernUserId": sender.tag], btn: sender)
        } else {
            self.delegate?.attentionUser(parameters: ["concernUserId": sender.tag], btn: sender)
        }
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    
}
